//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.cj.network;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.concurrent.TimeUnit;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.OkHttpClient.Builder;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class OlyHttp {
    private static volatile OlyHttp INSTANCE = null;
    private OkHttpClient okHttpClient;
    private Retrofit retrofit;
    private int timeReadOut = 25;
    private int timeConnOut = 25;
    private String baseUrl = "http";
    private Interceptor[] muiltUrl;

    private OlyHttp() {
    }

    public static OlyHttp newInstance() {
        if (INSTANCE == null) {
            Class var0 = OlyHttp.class;
            synchronized(OlyHttp.class) {
                if (INSTANCE == null) {
                    INSTANCE = new OlyHttp();
                }
            }
        }

        return INSTANCE;
    }

    public OlyHttp setTimeReadOut(int timeReadOut) {
        this.timeReadOut = timeReadOut;
        return this;
    }

    public OlyHttp setTimeConnOut(int timeConnOut) {
        this.timeConnOut = timeConnOut;
        return this;
    }

    public OlyHttp setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
        return this;
    }

    public OlyHttp setMuiltUrl(Interceptor... interceptors) {
        this.muiltUrl = interceptors;
        return this;
    }

    public void build() {
        Builder builder = new Builder();
        if (this.muiltUrl != null && this.muiltUrl.length > 0) {
            Interceptor[] var2 = this.muiltUrl;
            int var3 = var2.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                Interceptor interceptor = var2[var4];
                builder.addInterceptor(interceptor);
            }
        }

        builder.retryOnConnectionFailure(true).readTimeout((long)this.timeReadOut, TimeUnit.SECONDS).connectTimeout((long)this.timeConnOut, TimeUnit.SECONDS);
        this.okHttpClient = builder.build();
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.serializeNulls();
        Gson gson = gsonBuilder.create();
        this.retrofit = (new Retrofit.Builder()).baseUrl(this.baseUrl).client(this.okHttpClient).addConverterFactory(GsonConverterFactory.create(gson)).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
    }

    public <T> T create(Class<T> service) {
        return this.retrofit.create(service);
    }
}
